// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Ml
{
	public sealed partial class Ensemble
	{
		[JsonInclude]
		[JsonPropertyName("aggregate_output")]
		public Elastic.Clients.Elasticsearch.Ml.AggregateOutput? AggregateOutput { get; set; }

		[JsonInclude]
		[JsonPropertyName("classification_labels")]
		public IEnumerable<string>? ClassificationLabels { get; set; }

		[JsonInclude]
		[JsonPropertyName("feature_names")]
		public IEnumerable<string>? FeatureNames { get; set; }

		[JsonInclude]
		[JsonPropertyName("target_type")]
		public string? TargetType { get; set; }

		[JsonInclude]
		[JsonPropertyName("trained_models")]
		public IEnumerable<Elastic.Clients.Elasticsearch.Ml.TrainedModel> TrainedModels { get; set; }
	}

	public sealed partial class EnsembleDescriptor : SerializableDescriptorBase<EnsembleDescriptor>
	{
		internal EnsembleDescriptor(Action<EnsembleDescriptor> configure) => configure.Invoke(this);
		public EnsembleDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.Ml.AggregateOutput? AggregateOutputValue { get; set; }

		private AggregateOutputDescriptor AggregateOutputDescriptor { get; set; }

		private Action<AggregateOutputDescriptor> AggregateOutputDescriptorAction { get; set; }

		private IEnumerable<string>? ClassificationLabelsValue { get; set; }

		private IEnumerable<string>? FeatureNamesValue { get; set; }

		private string? TargetTypeValue { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.Ml.TrainedModel> TrainedModelsValue { get; set; }

		private TrainedModelDescriptor TrainedModelsDescriptor { get; set; }

		private Action<TrainedModelDescriptor> TrainedModelsDescriptorAction { get; set; }

		private Action<TrainedModelDescriptor>[] TrainedModelsDescriptorActions { get; set; }

		public EnsembleDescriptor AggregateOutput(Elastic.Clients.Elasticsearch.Ml.AggregateOutput? aggregateOutput)
		{
			AggregateOutputDescriptor = null;
			AggregateOutputDescriptorAction = null;
			AggregateOutputValue = aggregateOutput;
			return Self;
		}

		public EnsembleDescriptor AggregateOutput(AggregateOutputDescriptor descriptor)
		{
			AggregateOutputValue = null;
			AggregateOutputDescriptorAction = null;
			AggregateOutputDescriptor = descriptor;
			return Self;
		}

		public EnsembleDescriptor AggregateOutput(Action<AggregateOutputDescriptor> configure)
		{
			AggregateOutputValue = null;
			AggregateOutputDescriptor = null;
			AggregateOutputDescriptorAction = configure;
			return Self;
		}

		public EnsembleDescriptor ClassificationLabels(IEnumerable<string>? classificationLabels)
		{
			ClassificationLabelsValue = classificationLabels;
			return Self;
		}

		public EnsembleDescriptor FeatureNames(IEnumerable<string>? featureNames)
		{
			FeatureNamesValue = featureNames;
			return Self;
		}

		public EnsembleDescriptor TargetType(string? targetType)
		{
			TargetTypeValue = targetType;
			return Self;
		}

		public EnsembleDescriptor TrainedModels(IEnumerable<Elastic.Clients.Elasticsearch.Ml.TrainedModel> trainedModels)
		{
			TrainedModelsDescriptor = null;
			TrainedModelsDescriptorAction = null;
			TrainedModelsDescriptorActions = null;
			TrainedModelsValue = trainedModels;
			return Self;
		}

		public EnsembleDescriptor TrainedModels(TrainedModelDescriptor descriptor)
		{
			TrainedModelsValue = null;
			TrainedModelsDescriptorAction = null;
			TrainedModelsDescriptorActions = null;
			TrainedModelsDescriptor = descriptor;
			return Self;
		}

		public EnsembleDescriptor TrainedModels(Action<TrainedModelDescriptor> configure)
		{
			TrainedModelsValue = null;
			TrainedModelsDescriptor = null;
			TrainedModelsDescriptorActions = null;
			TrainedModelsDescriptorAction = configure;
			return Self;
		}

		public EnsembleDescriptor TrainedModels(params Action<TrainedModelDescriptor>[] configure)
		{
			TrainedModelsValue = null;
			TrainedModelsDescriptor = null;
			TrainedModelsDescriptorAction = null;
			TrainedModelsDescriptorActions = configure;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (AggregateOutputDescriptor is not null)
			{
				writer.WritePropertyName("aggregate_output");
				JsonSerializer.Serialize(writer, AggregateOutputDescriptor, options);
			}
			else if (AggregateOutputDescriptorAction is not null)
			{
				writer.WritePropertyName("aggregate_output");
				JsonSerializer.Serialize(writer, new AggregateOutputDescriptor(AggregateOutputDescriptorAction), options);
			}
			else if (AggregateOutputValue is not null)
			{
				writer.WritePropertyName("aggregate_output");
				JsonSerializer.Serialize(writer, AggregateOutputValue, options);
			}

			if (ClassificationLabelsValue is not null)
			{
				writer.WritePropertyName("classification_labels");
				JsonSerializer.Serialize(writer, ClassificationLabelsValue, options);
			}

			if (FeatureNamesValue is not null)
			{
				writer.WritePropertyName("feature_names");
				JsonSerializer.Serialize(writer, FeatureNamesValue, options);
			}

			if (!string.IsNullOrEmpty(TargetTypeValue))
			{
				writer.WritePropertyName("target_type");
				writer.WriteStringValue(TargetTypeValue);
			}

			if (TrainedModelsDescriptor is not null)
			{
				writer.WritePropertyName("trained_models");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, TrainedModelsDescriptor, options);
				writer.WriteEndArray();
			}
			else if (TrainedModelsDescriptorAction is not null)
			{
				writer.WritePropertyName("trained_models");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new TrainedModelDescriptor(TrainedModelsDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (TrainedModelsDescriptorActions is not null)
			{
				writer.WritePropertyName("trained_models");
				writer.WriteStartArray();
				foreach (var action in TrainedModelsDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new TrainedModelDescriptor(action), options);
				}

				writer.WriteEndArray();
			}
			else
			{
				writer.WritePropertyName("trained_models");
				JsonSerializer.Serialize(writer, TrainedModelsValue, options);
			}

			writer.WriteEndObject();
		}
	}
}